package vexe.web.thn.lib;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Enumeration;

import javax.servlet.http.HttpServletRequest;

public class BeanObject {
	public static Object Bean(HttpServletRequest request,Object object){
		Field[]  field= object.getClass().getDeclaredFields();
		Method[] methods=object.getClass().getMethods(); 
		Enumeration<?> e=request.getParameterNames();
			while(e.hasMoreElements()){
				String ParameterNames = "";				
				ParameterNames=(String)e.nextElement();
				for(int i=0;i<field.length;i++){
					if(field[i].getName().equals(ParameterNames)){						
						for(int j=0;j<methods.length;j++){
							if(methods[j].getName().toUpperCase().equals(("set"+ParameterNames).toUpperCase())){
								try {
									methods[j].invoke(object, request.getParameter(ParameterNames));
								} catch (IllegalArgumentException e1) {
									// TODO Auto-generated catch block
									e1.printStackTrace();
									return null;
								} catch (IllegalAccessException e1) {
									// TODO Auto-generated catch block
									e1.printStackTrace();
									return null;
								} catch (InvocationTargetException e1) {
									// TODO Auto-generated catch block
									e1.printStackTrace();
									return null;
								}
							}
						}
					}
				}
			}
		return object;
	}
}
